import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { COLUMN_INFO, COLUMN_TREE_LIST, CONTENT_DETAIL, CONTENT_DETAIL2, CONTENT_LIST } from '../api/information';

@Injectable({providedIn: 'root'})
export class InformationService {
  
  // public columnTreeList$ = new Subject<ColumnData[]>()
  public columnTreeList$ = new Subject<ColumnData[]>()
  public columnTree: ColumnData[] = []
  constructor(
    private http: HttpClient
  ) { }

  // 获取栏目信息
  _getColumnInfo(code: string): Observable<any>{
    return this.http.get(COLUMN_INFO + code)
  }

  _getColumnList(storeId: string): Observable<any>{
    return this.http.get(COLUMN_TREE_LIST + storeId)
  }

  /**
   * 根据栏目编码文章列表与详情
   * @param code 栏目编码
   * @param page 页码
   * @param size 条数
   * @param withOffSpring 是否查询后代
   * @param permission 是否权限
   * @returns 
   */
  _getContentList(code: string, page = 0, size = 7, withOffSpring = false, permission = false): Observable<any>{
    const params = {
      code, page, size, withOffSpring, permission
    }
    return this.http.get(CONTENT_LIST, { params: new HttpParams({ fromObject:  params}) })
  }

  _getContentDetail(id: string): Observable<any>{
    const params = {
      id
    }
    return this.http.get(CONTENT_DETAIL, { params: new HttpParams({ fromObject:  params}) })
  }
}

// 公告信息列表
export interface ArticleInfoData {
  "subtitle": string,
  "deletiontime": string,
  "approvalstatus": string,
  "columnid": string,
  "creatoruser": string,
  "enablecopy": number,
  "enableanonymous": boolean,
  "deleteruserid": string,
  "entityid": string,
  "title": string,
  "isdeleted": boolean,
  "content": string,
  "tenantid": string,
  "creatoruserid": string,
  "channelName": string,
  "id": string,
  "creationtime": string,
  "lastmodifieruserid": string,
  "lastmodificationtime": string,
  "enablecomment": string,
  "seclevelname": string,
  "seclevel": string,
  "channelCode": string
}

// 栏目信息
export interface ColumnData {
  "id": string,
  "parentId": string,
  "path": string,
  "sortOrder": number,
  "storeId": string,
  "code": string,
  "name": string,
  "approvalId": string,
  "imgFileId": string,
  "description": string,
  "allowCreateContent": boolean,
  "entityId": string,
  "contentCount": string,
  "publishedCount": string,
  "appId": string,
  "title": string,
  "key": string,
  "children": ColumnData[],
  "level": number,
  "isLeaf": boolean
}